package services.robot.concrete

import collection.mutable.Buffer
import services.robot.common._
import scala.collection.JavaConversions._

class InvaskSiteNode(override val url: String, title: String) extends SiteNode(url, title) {

  class InvaskProductsPage(url: String, pageNumber: Int) extends ProductsPage(url, pageNumber) {
    def items: Buffer[ProductNode] = {
      for (el <- $(".kletka-2 ul li div.novinki-content"))
        yield ProductNode(el.select("h3 a").attr("href"), el.select("h3 a").text.trim())
    }
    def nextPageExists:Boolean = {
      for (el <- $(".page-link a"))
        if ((pageNumber + 1).toString.equals(el.text.trim))
          return true
      false
    }
  }
  def getCategories = {
    for (el <- $(".box-kategory.brand-category-box li a"))
      yield new InvaskSiteNode("http://invask.ru" + el.attr("href"), el.text.trim)
  }
  def getProductsPage(pageNumber: Int) = {
    new InvaskProductsPage("%1$s/0/%2$s".format(url, pageNumber), pageNumber)
  }
}
